(defpackage :data-input-examples
  (:use :cl)
  (:export :define-data-input-examples))

(in-package :data-input-examples)


(defun define-checkbox-example ()
  (spinneret:with-html
    (:div (:h3 "Checkbox")
          (:div (:h4 "Checkbox")
                (dui:checkbox "checkbox" t "I'm a label")
                (dui:checkbox "checkbox" nil))
          (:div (:h4 "With label and form-control")
                (:div :class "form-control"
                      (:label :class "label cursor-pointer"
                              (:span :class "label-text" "Remember me")
                              (dui:checkbox "checkbox" t))))
          (:div (:h4 "Primary color")
                (:div :class "form-control"
                      (:label :class "label cursor-pointer"
                              (:span :class "label-text" "Remember me")
                              (dui:checkbox "checkbox checkbox-primary" t))))
          (:div (:h4 "Disabled")
                (dui:checkbox "checkbox" nil :disabled t))
          (:div (:h4 "Disabled")
                (dui:checkbox "checkbox" t :disabled t)))
    ))

(defun define-file-input-example ()
  (spinneret:with-html
    (:div (:h3 "File input")
          (:div (:h4 "File input")
                (dui:file-input "file-input file-input-ghost w-full max-w-xs"))
          (:div (:h4 "File input with border")
                (dui:file-input "file-input file-input-bordered w-full max-w-xs"))
          (:div (:h4 "With form-control and labels")
                (:div :class "form-control w-full max-w-xs"
                      (:label :class "label cursor-pointer" ;; comment this line can get the same result as that in official website
                              (:div :class "label"
                                    (:span :class "label-text" "Pick a file")
                                    (:span :class "label-text-alt" "Alt label"))
                              (dui:file-input "file-input file-input-bordered w-full max-w-xs")
                              (:div :class "label"
                                    (:span :class "label-text-alt" "Alt label")
                                    (:span :class "label-text-alt" "Alt label")))))
          (:div (:h4 "Primary color")
                (dui:file-input "file-input file-input-bordered file-input-primary w-full max-w-xs")))
    ))

(defun define-radio-example ()
  (spinneret:with-html
    (:div (:h3 "Radio")
          (:div (:h4 "Radio")
                (:div
                 (dui:radio "radio" "radio-1" t)
                 (dui:radio "radio" "radio-1" nil)))
          (:div (:h4 "With label")
                (:div
                 (dui:radio "radio" "radio-1" t   "One")
                 (dui:radio "radio" "radio-1" nil "Two")))
          (:div (:h4 "Primary color")
                (:div
                 (dui:radio "radio radio-primary" "radio-2" t)
                 (dui:radio "radio radio-primary" "radio-2" nil)))
          (:div (:h4 "Disabled")
                (:div
                 (dui:radio "radio radio-primary" "radio-9" t   :disabled t)
                 (dui:radio "radio radio-primary" "radio-9" nil :disabled t)))
          (:div (:h4 "With label and form-control and custom colors!")
                (:div :class "form-control"
                      (:label :class "label cursor-pointer"
                              (:span :class "label-text" "Red pill")
                              (dui:radio "radio checked:bg-red-500" "radio-10" t)))
                (:div :class "form-control"
                      (:label :class "label cursor-pointer"
                              (:span :class "label-text" "Blue pill")
                              (dui:radio "radio checked:bg-blue-500" "radio-10" t))))
          )))

(defun define-select-example ()
  (spinneret:with-html
    (:div (:h3 "Select")
          (:div (:h4 "Select")
                (dui:select "select select-bordered w-full max-w-xs"
                  ((dui:select-option "Who shot first?" T T)
                   (dui:select-option "Han Solo")
                   (dui:select-option "Greedo")
                   )))
          (:div (:h4 "With form-control and labels")
                (:div :class "form-control w-full max-w-xs"
                      (:div :class "label"
                            (:span :class "label-text" "Pick the best fantasy franchise")
                            (:span :class "label-text-alt" "Alt label"))
                      (dui:select "select select-bordered"
                        ((dui:select-option "Pick one" T T)
                         (dui:select-option "Star Wars")
                         (dui:select-option "Harry Potter")
                         (dui:select-option "Lord of the Rings")
                         (dui:select-option "Planet of the Apes")
                         (dui:select-option "Star Trek")))
                      (:div :class "label"
                            (:span :class "label-text-alt" "Alt label")
                            (:span :class "label-text-alt" "Alt label"))))
          (:div (:h4 "Primary color")
                (dui:select "select select-primary w-full max-w-xs"
                  ((dui:select-option "Who shot first?" T T)
                   (dui:select-option "Han Solo")
                   (dui:select-option "Greedo")
                   )))
          (:div (:h4 "Disabled")
                (dui:select "select w-full max-w-xs"
                  ((dui:select-option "Who shot first?" T T)
                   (dui:select-option "Han Solo")
                   (dui:select-option "Greedo"))
                  :disabled t))
          )))

(defun define-text-input-example ()
  (spinneret:with-html
    (:div (:h3 "Text Input")
          (:div (:h4 "Text Input")
                (dui:input "input w-full max-w-xs" "text" "Type here"))
          (:div (:h4 "Text input with border")
                (dui:input "input input-bordered w-full max-w-xs" "text" "Type here"))
          (:div (:h4 "Text input with icon inside")
                (:label :class "input input-bordered flex items-center gap-2"
                        (dui:input "grow" "text" "Search")
                        (icons:mag-glass))
                (:label :class "input input-bordered flex items-center gap-2"
                        (icons:mag-glass)
                        (dui:input "grow" "text" "Search")))
          (:div (:h4 "Text input with text label inside")
                (:label :class "input input-bordered flex items-center gap-2"
                        "Name"
                        (dui:input "grow" "text" "Search"))
                (:label :class "input input-bordered flex items-center gap-2"
                        (dui:input "grow" "text" "Search")
                        (dui:kbd "kbd kbd-sm" "⌘")))
          (:div (:h4 "Primary color")
                (dui:input "input input-bordered input-primary w-full max-w-xs" "text" "Type here" ))
          (:div (:h4 "Disabled")
                (dui:input "input input-bordered w-full max-w-xs" "text" "Type here" :disabled t))
          )))

(defun define-textarea-example ()
  (spinneret:with-html
    (:div (:h3 "Textarea")
          (:div (:h4 "Textarea")
                (dui:textarea "textarea" "Bio"))
          (:div (:h4 "Textarea with border")
                (dui:textarea "textarea textarea-bordered" "Bio"))
          (:div (:h4 "Primary color")
                (dui:textarea "textarea textarea-primary" "Bio"))
          (:div (:h4 "Sizes")
                (dui:textarea "textarea textarea-bordered textarea-xs w-full max-w-xs" "Bio")
                (dui:textarea "textarea textarea-bordered textarea-sm w-full max-w-xs" "Bio")
                (dui:textarea "textarea textarea-bordered textarea-md w-full max-w-xs" "Bio")
                (dui:textarea "textarea textarea-bordered textarea-lg w-full max-w-xs" "Bio"))
          (:div (:h4 "Disabled")
                (dui:textarea "textarea" "Bio" :disabled t))
          )))

(defun define-toggle-example ()
  (spinneret:with-html
    (:div (:h3 "Toggle")
          (:div (:h4 "Toggle")
                (dui:toggle "toggle" t))

          )))



(defun define-data-input-examples ()
  (spinneret:with-html
    (:div
     (define-checkbox-example)
     ;; ...
     )))


(defun compile-checkbox-example ()
  (spinneret:with-html-string
    (define-checkbox-example)))

(defun compile-file-input-example ()
  (spinneret:with-html-string
    (define-file-input-example)))

(defun compile-radio-example ()
  (spinneret:with-html-string
    (define-radio-example)))

(defun compile-select-example ()
  (spinneret:with-html-string
    (define-select-example)))

(defun compile-text-input-example ()
  (spinneret:with-html-string
    (define-text-input-example)))

(defun compile-textarea-example ()
  (spinneret:with-html-string
    (define-textarea-example)))

(defun compile-toggle-example ()
  (spinneret:with-html-string
    (define-toggle-example)))


(easy-routes:defroute data-input-checkbox ("/data-input/checkbox" :method :get) ()
  (compile-checkbox-example))

(easy-routes:defroute data-input-file-input ("/data-input/file-input" :method :get) ()
  (compile-file-input-example))

(easy-routes:defroute data-input-radio ("/data-input/radio" :method :get) ()
  (compile-radio-example))

(easy-routes:defroute data-input-select ("/data-input/select" :method :get) ()
  (compile-select-example))

(easy-routes:defroute data-input-text-input ("/data-input/input" :method :get) ()
  (compile-text-input-example))

(easy-routes:defroute data-input-textarea ("/data-input/textarea" :method :get) ()
  (compile-textarea-example))

(easy-routes:defroute data-input-toggle ("/data-input/toggle" :method :get) ()
  (compile-toggle-example))
